var _o98;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ConstValue = require("ConstValue");
var $2GameEvent = require("GameEvent");
var $2Platformconf = require("Platformconf");
var l = cc._decorator.ccclass;
var def_TT_InterstitialMgr = _o98 = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.interstitialAd = null;
    this.adid = "";
  }
  return babel_createClass(_ctor, [{
    key: "init",
    value: function init() {
      this.adid = $2Platformconf.default.Instance.getconfig().TTGame.Interstitial[0];
      console.log(" this.adid------------", this.adid);
      this.create();
    }
  }, {
    key: "create",
    value: function create() {
      var _this84 = this;
      console.log(" this.adid", this.adid);
      var e = this;
      if (null != this.interstitialAd) {
        this.interstitialAd.destroy();
        this.interstitialAd = null;
      }
      var t = window.tt.createInterstitialAd({
        adUnitId: e.adid
      });
      t.onLoad(function () {
        console.log("插屏拉取成功");
        $2GameEvent.default.sendEvent("adevent", {
          type: "splash",
          action: "get",
          result: "success",
          adid: e.adid
        });
        _this84.interstitialAd = t;
      });
      t.onError(function (t) {
        console.log("插屏拉取报错:", t);
        $2GameEvent.default.sendEvent("adevent", {
          type: "splash",
          action: "get",
          result: "fail",
          adid: e.adid
        });
      });
      t.onClose(function () {
        if (null != _this84.interstitialAd) {
          _this84.interstitialAd.destroy();
          _this84.interstitialAd = null;
          setTimeout(function () {
            "" != _this84.adid && _this84.create();
          }, 5e3);
        }
        $2ConstValue.ConstValue.InterAdIntervalTime += $2ConstValue.ConstValue.INSERT_VIDEO_INTERVAL_TT;
      });
    }
  }, {
    key: "show",
    value: function show(e) {
      var _this85 = this;
      if (window.tt) {
        var _t46 = window.tt.getSystemInfoSync().appName;
        console.log("插屏开始判断平台：", _t46);
        if ("Toutiao" === _t46 || "Douyin" === _t46) {
          console.log("插屏开始创建：", e);
          this.close();
          this.interstitialAd = window.tt.createInterstitialAd({
            adUnitId: e
          });
          if (!this.interstitialAd) {
            return;
          }
          this.interstitialAd.onClose(this.close.bind(this));
          this.interstitialAd.load().then(function () {
            _this85.interstitialAd.show();
            $2GameEvent.default.sendEvent("interstitial_show");
            console.log("插屏拉取成功", "插屏观看次数+1");
          }).catch(function (e) {
            console.log("插屏", e);
            _this85.close();
          });
        }
      }
    }
  }, {
    key: "close",
    value: function close() {
      if (this.interstitialAd) {
        this.interstitialAd.offClose(this.close.bind(this));
        this.interstitialAd.destroy();
        this.interstitialAd = null;
      }
      $2ConstValue.ConstValue.InterAdIntervalTime += $2ConstValue.ConstValue.INSERT_VIDEO_INTERVAL_TT;
    }
  }], [{
    key: "Instance",
    get() {
      _o98._instance || (_o98._instance = new _o98());
      return _o98._instance;
    }
  }]);
}();
def_TT_InterstitialMgr = _o98 = cc__decorate([l], def_TT_InterstitialMgr);
exports.default = def_TT_InterstitialMgr;